package com.seventh.parkingrent.service.impl;

import com.seventh.parkingrent.controller.form.EvaluationForm;
import com.seventh.parkingrent.dao.RentMessageMapper;
import com.seventh.parkingrent.domain.Evaluation;
import com.seventh.parkingrent.dao.EvaluationMapper;
import com.seventh.parkingrent.domain.RentMessage;
import com.seventh.parkingrent.service.IEvaluationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-08-24
 */
@Service
public class EvaluationServiceImpl extends ServiceImpl<EvaluationMapper, Evaluation> implements IEvaluationService {
    @Autowired
    private EvaluationMapper evaluationMapper;
    @Autowired
    private RentMessageMapper rentMessageMapper;

    @Override
    public boolean addevaluation(EvaluationForm evaluationForm) {
        Evaluation evaluation = new Evaluation();
        BeanUtils.copyProperties(evaluationForm,evaluation);
        int i = evaluationMapper.insert(evaluation);
        Integer zlid = evaluation.getEvaluationId();
        RentMessage rentMessage = rentMessageMapper.selectById(evaluationForm.getRentid());
        rentMessage.setZlid(zlid);
        rentMessageMapper.updateById(rentMessage);
        return i>0;
    }

    @Override
    public Evaluation getevaluationByRentid(Integer rentid) {
        RentMessage rentMessage = rentMessageMapper.selectById(rentid);
        Integer zlid = rentMessage.getZlid();
        if (zlid==null){
            return null;
        }
        return evaluationMapper.selectById(zlid);
    }
}
